
# load packages 
packages <- c(
  "tidyverse",
  "lfe",
  "ggplot2", 
  "ggthemes", 
  "readxl",
  "scales", 
  "dplyr",
  "readr", 
  "RCurl"
)

pacman::p_load(packages, 
               character.only = TRUE, 
               install = FALSE)

# load df 1
knowFreq <- read_csv("/Users/ankushi/Desktop/PSPSI RA/PSPSI/knowFreq.csv")

# clean df 1
knowFreq <- knowFreq[ -c(1) ]

knowFreq$domain <- as.factor(knowFreq$domain)
levels(knowFreq$domain)

knowFreq$domain <- factor(knowFreq$domain, 
                          levels=c('Career Opportunities', 'Skills Gained in PhD', 'Publishing', 'Faculty Advising', 'Funding',
                                   'Networking', 'Research Methods', 'Subfields',
                                   'Structure of PhD', 'Other Resources', 'Institutional Resources', 
                                   'Application Process', 'Application Content'))

knowFreq <- knowFreq %>% 
  mutate(endPt = if_else(after == 1, freq, 0))

knowFreq$endPt[knowFreq$endPt == 0] <- NA


knowFreq$n <- as.integer(knowFreq$n)
knowFreq$after <- as.integer(knowFreq$after)

knowFreq <- knowFreq %>% 
  mutate(endPt2 = if_else(after == 1, n, as.integer(0)))

knowFreq$endPt2[knowFreq$endPt2 == 0] <- NA

knowFreq$after <- as.factor(knowFreq$after)
knowFreq$after <- factor(knowFreq$after, levels=c('1', '0'))

# plot figure 2
theme_set(theme_fivethirtyeight()) 
plot222 <- ggplot(knowFreq) +
  geom_col(aes(x=n, y=domain, fill=after)) +
  theme(legend.title = element_blank(),
        legend.background = element_blank(),
        legend.key = element_blank(),
        legend.key.size = unit(0.5, "cm"),
        legend.text = element_text(size = 20)) + 
  theme(
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    panel.background = element_blank(), 
    plot.background = element_blank()) +
  labs(
    title = "Fig. 2: Number of Participants Familiar with PhD Applications and Programs") +
  theme(
    plot.title = element_text(size = 24, face = "bold", hjust = 0.5),
    plot.subtitle = element_text(size = 10, hjust = 0.5, face = "bold",),
    plot.caption = element_text(face = "italic", size = 5, hjust = 1),
  ) +
  theme(axis.text.x = element_text(angle = 360, size=20), 
        axis.text.y = element_text(angle = 360, size=20)) +
  scale_fill_grey(labels = c("Post-Institute", "Pre-Institute"))

plot222 + guides(fill = guide_legend(reverse = TRUE))


# load df 2 
evalDf <- read_csv("/Users/ankushi/Desktop/PSPSI RA/PSPSI/evalDf.csv")

# clean df 2
evalDf <- evalDf[ -c(1) ]


evalDf$domain <- factor(evalDf$domain, 
                            levels=c('Conversations with Other Participants','Conversations with PhD Mentors',
                                     'Conversations with Faculty', 
                                     'Presentations & Research Feedback',
                                     'Readings', 'Breakout Sessions', 'Panels & Roundtables'
                            ))

evalDf$ques <- factor(evalDf$ques, 
                      levels=c('Improving Knowledge as a Political Science Researcher',
                               'Understanding a Political Science PhD'))


# plot figure 1
evalPlot <- ggplot(evalDf) +
  geom_col(aes(x = n, y = domain, group=ques, fill=ques), width = 0.6, position = position_dodge(0.7)) +
  theme(
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    panel.background = element_blank(), 
    plot.background = element_blank()) +
  labs(
    title = "Fig. 1: Evaluation of PS-PSI Program",
    subtitle = "Number of Participants Responding with Helpful/Very Helpful") +
  theme(
    plot.title = element_text(size = 24, face = "bold", hjust = 0.5),
    plot.subtitle = element_text(size = 18, hjust = 0.5, face = "bold",),
    plot.caption = element_text(face = "italic", size = 5, hjust = 1),
  ) +
  theme(axis.text.x = element_text(angle = 360, size=20), 
        axis.text.y = element_text(angle = 360, size=18)) +
  theme(axis.title.x = element_blank()) +
  scale_fill_grey() +
  theme(legend.title = element_blank(),
        legend.background = element_blank(),
        legend.key = element_blank(),
        legend.key.size = unit(0.5, "cm"),
        legend.text = element_text(size = 18))

evalPlot + guides(fill = guide_legend(reverse = TRUE))




